package com.xbfinal.staservice.schedule;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.xbfinal.staservice.service.StatisticsDailyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Title: ScheduledTask
 * @Author 笑霸fianl
 * @Package com.xbfinal.staservice.schedule
 * @Date 2023/3/12 15:12
 * @描述:定时任务类
 */
@Component
@Slf4j
public class ScheduledTask {


    @Autowired
    private StatisticsDailyService statService;


    /**
     * 每天凌晨1点 把前一天的数据添加
     */
    @Scheduled(cron = "0 0 1 * * ?")//每5秒执行一直
    public void task(){
        log.info("==============定时任务执行了");
        //获取天的日期
        DateTime yesterday = DateUtil.yesterday();
        statService.registerCount(yesterday.toDateStr());
    }
}
